<template>
<!-- 楼宇管理 -->
    <div class="BuildingManagement">
        <div class="query">
             <el-select
                v-model="value2"
                multiple
                collapse-tags
                style="margin-left: 20px;"
                placeholder="请选择" class="selection">
                <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
                </el-option>
            </el-select>
            <!-- 查询和重置按钮 -->
            <el-button type="primary" class="chaxun" @click="select"><i class="el-icon-search" ></i>查询</el-button>
            <el-button class="reaseat" @click="reasert"><i class="el-icon-refresh-right" ></i>重置</el-button>
        </div>
        <!-- 数据表格 -->
        <div class="datalists">
            <div class="datalistsname">数据列表</div>
            <!-- 导入数据 -->
            <el-button type="primary" class="ImportData" @click="ImportData">导入数据</el-button>
            <!-- 添加按钮 -->
            <el-button type="primary" class="append" @click="append"><i class="el-icon-plus"></i>添加商铺</el-button>
            <!-- 批量添加 -->
            <el-button type="primary" class="appends" @click="appends"><i class="el-icon-folder-add"></i>批量添加</el-button>
            <!-- 数据表格 -->
            <div class="datatable">
                <el-table
                :data="tableData"
                border
                stripe
                style="width: 100%">
                    <el-table-column
                    prop="date"
                    label="序号"
                    width="95">
                    </el-table-column>
                    <el-table-column
                    prop="Belongingcommunity"
                    label="所属小区"
                    width="104">
                    </el-table-column>
                    <el-table-column
                    prop="Productarea"
                    label="商品区域"
                    width="124">
                    </el-table-column>
                    <el-table-column
                    prop="ShopNumber"
                    label="商铺编号"
                    width="77">
                    </el-table-column>
                    <el-table-column
                    prop="Floorlocation"
                    label="所在楼层"
                    width="108">
                    </el-table-column>
                    <el-table-column
                    prop="buildingarea"
                    label="建筑面积"
                    width="108">
                    </el-table-column>
                    <el-table-column
                    prop="usablearea"
                    label="使用面积"
                    width="102">
                    </el-table-column>
                    <el-table-column
                    prop="Housetype"
                    label="房屋类型"
                    width="108">
                    </el-table-column>
                    <el-table-column
                    prop="Housingstatus"
                    label="房屋状态"
                    width="124">
                    </el-table-column>
                    <el-table-column
                    prop="operate"
                    label="操作"
                    width="267">
                        <template slot-scope="scope">
                            <i class="el-icon-office-building"></i>
                            <span style="margin-left: 5px;margin-right:5px" @click="building(scope.row)">{{ scope.row.edit }}</span>
                            <i class="el-icon-edit"></i>
                            <span style="margin-left: 5px;margin-right:5px" @click="edit(scope.row.date)">{{ scope.row.del }}</span>
                            <i class="el-icon-delete"></i>
                            <span style="margin-left: 5px;margin-right:5px" @click="del(scope.row.date)">{{ scope.row.opertes}}</span>
                        </template>
                    </el-table-column>
                    
                </el-table>
                <!-- 分页器 -->
                <div class="block">
                    <el-pagination
                    background
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page.sync="currentPage2"
                    :page-sizes="[10, 20, 30, 40]"
                    :page-size="50"
                    layout=" prev, pager, next, sizes,jumper"
                    :total="totalpage">
                    </el-pagination>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    data(){
        return{
            options: [{
            value: '选项1',
            label: '万达文旅城'
            }, {
            value: '选项2',
            label: '碧桂园'
            }, {
            value: '选项3',
            label: '万象城'
            }, {
            value: '选项4',
            label: '龙须面'
            }, {
            value: '选项5',
            label: '北京烤鸭'
            }],
            value2: [],
            // tableData: [
            //     {
            //         date: '1',
            //         Belongingcommunity: '万象城',
            //         Productarea: '底商区域',
            //         ShopNumber:'A-021',
            //         Floorlocation:'1',
            //         buildingarea:'150㎡',
            //         usablearea:'150㎡',
            //         Housetype:'商铺',
            //         Housingstatus:"正常",
            //         edit:'绑定业主',
            //         del:'编辑',
            //         opertes:'删除',
            //     }, 
            //     {
            //         date: '1',
            //         Belongingcommunity: '万象城',
            //         Productarea: '底商区域',
            //         ShopNumber:'A-021',
            //         Floorlocation:'1',
            //         buildingarea:'150㎡',
            //         usablearea:'150㎡',
            //         Housetype:'商铺',
            //         Housingstatus:"正常",
            //         edit:'绑定业主',
            //         del:'编辑',
            //         opertes:'删除',
            //     }, 
            //     {
            //         date: '1',
            //         Belongingcommunity: '万象城',
            //         Productarea: '底商区域',
            //         ShopNumber:'A-021',
            //         Floorlocation:'1',
            //         buildingarea:'150㎡',
            //         usablearea:'150㎡',
            //         Housetype:'商铺',
            //         Housingstatus:"正常",
            //         edit:'绑定业主',
            //         del:'编辑',
            //         opertes:'删除',
            //     }, 
            //     {
            //         date: '1',
            //         Belongingcommunity: '万象城',
            //         Productarea: '底商区域',
            //         ShopNumber:'A-021',
            //         Floorlocation:'1',
            //         buildingarea:'150㎡',
            //         usablearea:'150㎡',
            //         Housetype:'商铺',
            //         Housingstatus:"正常",
            //         edit:'绑定业主',
            //         del:'编辑',
            //         opertes:'删除',
            //     }, 
            //     {
            //         date: '1',
            //         Belongingcommunity: '万象城',
            //         Productarea: '底商区域',
            //         ShopNumber:'A-021',
            //         Floorlocation:'1',
            //         buildingarea:'150㎡',
            //         usablearea:'150㎡',
            //         Housetype:'商铺',
            //         Housingstatus:"正常",
            //         edit:'绑定业主',
            //         del:'编辑',
            //         opertes:'删除',
            //     }, 
            //     {
            //         date: '1',
            //         Belongingcommunity: '万象城',
            //         Productarea: '底商区域',
            //         ShopNumber:'A-021',
            //         Floorlocation:'1',
            //         buildingarea:'150㎡',
            //         usablearea:'150㎡',
            //         Housetype:'商铺',
            //         Housingstatus:"正常",
            //         edit:'绑定业主',
            //         del:'编辑',
            //         opertes:'删除',
            //     }, 
            //     {
            //         date: '1',
            //         Belongingcommunity: '万象城',
            //         Productarea: '底商区域',
            //         ShopNumber:'A-021',
            //         Floorlocation:'1',
            //         buildingarea:'150㎡',
            //         usablearea:'150㎡',
            //         Housetype:'商铺',
            //         Housingstatus:"正常",
            //         edit:'绑定业主',
            //         del:'编辑',
            //         opertes:'删除',
            //     }, 
            //     {
            //         date: '1',
            //         Belongingcommunity: '万象城',
            //         Productarea: '底商区域',
            //         ShopNumber:'A-021',
            //         Floorlocation:'1',
            //         buildingarea:'150㎡',
            //         usablearea:'150㎡',
            //         Housetype:'商铺',
            //         Housingstatus:"正常",
            //         edit:'绑定业主',
            //         del:'编辑',
            //         opertes:'删除',
            //     }, 
            //     {
            //         date: '1',
            //         Belongingcommunity: '万象城',
            //         Productarea: '底商区域',
            //         ShopNumber:'A-021',
            //         Floorlocation:'1',
            //         buildingarea:'150㎡',
            //         usablearea:'150㎡',
            //         Housetype:'商铺',
            //         Housingstatus:"正常",
            //         edit:'绑定业主',
            //         del:'编辑',
            //         opertes:'删除',
            //     }, 
            //     {
            //         date: '1',
            //         Belongingcommunity: '万象城',
            //         Productarea: '底商区域',
            //         ShopNumber:'A-021',
            //         Floorlocation:'1',
            //         buildingarea:'150㎡',
            //         usablearea:'150㎡',
            //         Housetype:'商铺',
            //         Housingstatus:"正常",
            //         edit:'绑定业主',
            //         del:'编辑',
            //         opertes:'删除',
            //     }, 
            //     {
            //         date: '1',
            //         Belongingcommunity: '万象城',
            //         Productarea: '底商区域',
            //         ShopNumber:'A-021',
            //         Floorlocation:'1',
            //         buildingarea:'150㎡',
            //         usablearea:'150㎡',
            //         Housetype:'商铺',
            //         Housingstatus:"正常",
            //         edit:'绑定业主',
            //         del:'编辑',
            //         opertes:'删除',
            //     }, 
            //     {
            //         date: '1',
            //         Belongingcommunity: '万象城',
            //         Productarea: '底商区域',
            //         ShopNumber:'A-021',
            //         Floorlocation:'1',
            //         buildingarea:'150㎡',
            //         usablearea:'150㎡',
            //         Housetype:'商铺',
            //         Housingstatus:"正常",
            //         edit:'绑定业主',
            //         del:'编辑',
            //         opertes:'删除',
            //     }, 
            //     {
            //         date: '1',
            //         Belongingcommunity: '万象城',
            //         Productarea: '底商区域',
            //         ShopNumber:'A-021',
            //         Floorlocation:'1',
            //         buildingarea:'150㎡',
            //         usablearea:'150㎡',
            //         Housetype:'商铺',
            //         Housingstatus:"正常",
            //         edit:'绑定业主',
            //         del:'编辑',
            //         opertes:'删除',
            //     }, 
            //     {
            //         date: '1',
            //         Belongingcommunity: '万象城',
            //         Productarea: '底商区域',
            //         ShopNumber:'A-021',
            //         Floorlocation:'1',
            //         buildingarea:'150㎡',
            //         usablearea:'150㎡',
            //         Housetype:'商铺',
            //         Housingstatus:"正常",
            //         edit:'绑定业主',
            //         del:'编辑',
            //         opertes:'删除',
            //     }, 
            //     {
            //         date: '1',
            //         Belongingcommunity: '万象城',
            //         Productarea: '底商区域',
            //         ShopNumber:'A-021',
            //         Floorlocation:'1',
            //         buildingarea:'150㎡',
            //         usablearea:'150㎡',
            //         Housetype:'商铺',
            //         Housingstatus:"正常",
            //         edit:'绑定业主',
            //         del:'编辑',
            //         opertes:'删除',
            //     }, 
                
            // ],//数据表格数据
            currentPage2: 1,//分页器当前页
            pagelimit:10,   //每页显示多少
            totalpage:300,  //总页数
            tableData:[],   //表格数据
            datalists:[],   //总数据
        }
    },
    methods:{
        ImportData(){
            console.log("导入数据")
        },
        select(){
            console.log("查询")
        },
        reasert(){
            console.log("重置")
        },
        appends(){
            console.log("批量添加")
        },
        append(){
            console.log("添加")
            this.$router.push('/about/Addshop')
        },
        // 分页器打印
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
            this.pagelimit=val
        },
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`);
            
        },
        // 数据表格中楼宇管理、编辑和删除
        building(data){
            console.log("绑定业主",data.edit)
            if(data.edit=="绑定业主"){
                this.$router.push({
                    path:'/about/BingdingOwner',
                    query:{
                        data,
                        dataStore:'shopmengment'
                    }
                })
            }else{
                this.$confirm('此操作将解除业主绑定, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.$axios.post('http://127.0.0.1/ownercontact',{
                        date:data.date,
                        dataStore:'shopmengment'
                    }).then(res=>{
                        console.log(res)
                        this.datalists=res.data
                        this.tableData=res.data.slice((this.currentPage2-1)*this.pagelimit,this.pagelimit)
                        this.totalpage=res.data.length
                    }).catch(err=>{
                        console.log(err)
                    })
                    this.$message({
                        type: 'success',
                        message: '解除绑定成功!'
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消操作'
                    });          
                });
            }
            
            
        },
        edit(i){
            console.log('编辑')
            this.$router.push({
                path:'/about/Addshop',
                query:{
                    i
                }
            }
            )
        },
        // 删除
        del(i){
            console.log('删除',i)
            this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$axios.post('http://127.0.0.1/shoplistdel',{
                    date:i
                }).then(res=>{
                    console.log(res)
                    this.datalists.forEach((item,index)=>{
                        if(item.date==i){
                            this.datalists.splice(index,1)
                        }
                    })
                    this.tableData=this.datalists.filter(item=>item.date!=i).slice((this.currentPage2-1)*this.pagelimit,this.pagelimit*this.currentPage2)
                    if(this.totalpage>0){
                        this.totalpage--
                    }else{
                        this.totalpage=0
                    }
                    this.$message({
                        type: 'success',
                        message: '删除成功!'
                    });
                }).catch(err=>{
                    console.log(err)
                    this.$message.error('删除失败，请重试');
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });          
            });
        },
    },
    watch:{
        currentPage2:{
            handler(val,oldval){
                console.log((val-1)*this.pagelimit,val*this.pagelimit)
                this.tableData=this.datalists.slice((val-1)*this.pagelimit,val*this.pagelimit)
            },
            // immediate:true
        },
        pagelimit:{
            handler(val,oldval){
                console.log(val,oldval)
                this.tableData=this.datalists.slice((this.currentPage2-1)*val,val*this.currentPage2)
            }
        }
    },
    mounted(){
        this.$axios.get('http://127.0.0.1/shoplist').then(res=>{
            console.log(res.data,222222222)
            this.datalists=res.data
            this.tableData=res.data.slice((this.currentPage2-1)*this.pagelimit,this.pagelimit)
            this.totalpage=res.data.length
        }).catch(err=>{
            console.log(err)
        })
    }
};
</script>

<style lang="scss" scoped>
    .BuildingManagement{
        width: 1260px;
        margin: auto;
        height: 80vh;
        overflow: scroll;
        scrollbar-width: none;
        .query{
            width: 1260px;
            height: 95px;
            display: flex;
            align-items: center;
            background-color: #fff;
            box-sizing: border-box;
            border:  1px solid rgba(233, 233, 233, 1);
            padding-left: 20px;
            position: relative;
            .selection{
                width: 405px;
                ::v-deep .el-input__inner{
                    height: 35px;
                }
            }
            // 查询按钮
            .chaxun{
                width: 80px;
                height: 35px;
                margin-left: 20px;
                display: flex;
                justify-content: center;
                align-items: center;
                background-color: #0079fe !important;
                .el-icon-search{
                    font-size: 16px;
                    margin-right: 5px;
                }
            }
            .chaxun:hover{
                background-color: #66b1ff !important;
                color: #fff !important;
            }
            // 重置按钮
            .reaseat{
                width: 80px;
                height: 35px;
                margin-left: 20px;
                display: flex;
                justify-content: center;
                align-items: center;
                background-color: #fff !important;
                .el-icon-refresh-right{
                    font-size: 16px;
                    margin-right: 5px;
                }
            }
            .reaseat:hover{
                border-color: #0079fe !important;
                color: #0079fe !important;
            }
            
        }
        // 数据列表
        .datalists{
            width: 1260px;
            height: 1196px;
            padding: 0 20px;
            margin-top: 10px;
            background-color: #fff;
            border: 1px solid rgba(233, 233, 233, 1);
            position: relative;
            box-sizing: border-box;
            // 数据列表名字名称
            .datalistsname{
                margin-top: 40px;
                width: 57px;
                height: 18px;
                line-height: 18px;
                color: #666666;
                font-size: 14px;
            }
            // 添加数据按钮
            .append,.appends,.ImportData{
                width: 80px;
                height: 35px;
                position: absolute;
                right: 20px;
                top: 23px;
                display: flex;
                align-items: center;
                justify-content: center;
                background-color: #0079fe !important;
                .el-icon-plus,.el-icon-folder-add{
                    font-size: 16px;
                    margin-right: 5px;
                    font-weight: 700;
                }
            }
            .append:hover,.appends:hover,.ImportData:hover{
                background-color: #66b1ff !important;
                color: #fff !important;
            }
            .appends{
                position: absolute;
                padding: 0 2px;
                right: 120px;
                top: 23px;
            }
            .ImportData{
                position: absolute;
                right: 220px;
                top: 23px;
            }
            // 数据表格
            .datatable{
                margin-top: 20px;
                ::v-deep  .el-button:hover {
                        color: #FFF !important;
                        background-color: #409EFF !important;
                        border-color: #409EFF !important;
                }
                ::v-deep .has-gutter th{
                    height: 45px !important;
                    background-color: #f5f5f5;
                    box-sizing: border-box;
                    padding: 0 !important;
                    font-size: 14px;
                    color: #666666;
                    font-family: '微软雅黑 Bold', '微软雅黑 Regular', '微软雅黑' !important;
                }
                ::v-deep .el-table__row td{
                    height: 50px !important;
                    padding: 0 !important;
                }
                ::v-deep .el-table--enable-row-hover .el-table__body tr:hover>td.el-table__cell {
                    background-color: #f9f9f9;
                }
                ::v-deep .el-table__row .el-table__cell:nth-child(4){
                    text-align: center !important;
                    color: #999 !important;
                }
                ::v-deep .el-table__row .el-table__cell:nth-child(1){
                    color: #0079fe !important;
                }
                ::v-deep .el-table__row .el-table__cell:nth-child(2){
                    color: #666 !important;
                }
                ::v-deep .el-table__row .el-table__cell:nth-last-child(1){
                    text-align: center;
                    color: #0079fe;
                    // cursor: pointer;
                }
                ::v-deep .el-table__row .el-table__cell:nth-last-child(1) span:hover{
                    cursor: pointer;
                    text-decoration: underline !important;
                    // color: #4a4a4a;
                }
                ::v-deep .el-table__row .el-table__cell{
                    color: #666666;
                    font-size: 12px;
                }
                ::v-deep .el-table__row:hover{
                    background-color: inherit !important;
                }
                // 分页
                .block{
                    display: flex;
                    justify-content: end;
                    ::v-deep .el-pagination__sizes{
                        margin-left: 10px;
                        width: 80px;
                        height: 35px;
                        line-height: 35px;
                    }
                    ::v-deep .btn-prev,::v-deep .el-pager li,::v-deep .btn-next{
                        width: 35px;
                        height: 35px;
                        line-height: 35px;
                        background-color: #fff;
                        border: 1px solid rgba(228, 228, 228, 1);
                    }
                    ::v-deep .el-pager .active{
                        background-color: #0079fe !important;
                    }
                    ::v-deep .el-pager .active:hover{
                        color: #fff !important;
                        border: 1px solid rgb(228, 228, 228) !important;
                        box-sizing: border-box;
                    }
                    ::v-deep .el-pager li:hover,::v-deep .btn-prev:hover,::v-deep .btn-next:hover,::v-deep  .el-pagination__sizes .el-input .el-input__inner:hover {
                        border-color: #0079fe;
                        color: #0079fe;
                    }
                    ::v-deep .el-input--mini .el-input__inner,::v-deep .el-input--mini .el-input__icon {
                        height: 35px;
                        line-height: 35px;
                    }
                    ::v-deep .el-pagination .el-select .el-input {
                        width: 86px;
                        margin: 0 5px;
                    }
                    ::v-deep .el-pagination__jump{
                        height: 35px;
                        line-height: 35px;
                    }
                    ::v-deep .el-input__inner:focus {
                        border-color: rgb(228, 228, 228) !important;
                        outline: 0;
                    }
                }
            }
        }
    }
     

</style>